import threading
from threading import Condition


class XiaoAi(threading.Thread):
    def __init__(self, condition: Condition):
        super(XiaoAi, self).__init__(name="小爱")
        self.condition = condition

    def run(self):
        with self.condition:
            self.condition.wait()
            print("{}: 在".format(self.name))
            self.condition.notify()

            self.condition.wait()
            print("{}: 好啊".format(self.name))
            self.condition.notify()


class TianMao(threading.Thread):
    def __init__(self, condition: Condition):
        super(TianMao, self).__init__(name="天猫精灵")
        self.condition = condition

    def run(self):
        with self.condition:
            print("{}: 小爱同学".format(self.name))
            self.condition.notify()
            self.condition.wait()

            print("{}: 我们来对古诗吧".format(self.name))
            self.condition.notify()
            self.condition.wait()


if __name__ == '__main__':
    con = Condition()
    xiaoai = XiaoAi(con)
    tianmao = TianMao(con)

    xiaoai.start()
    tianmao.start()
